From : Serge Veugelers (sergev@cistron.nl)
Subject : Scanning a directory
> Sorry for asking again, but I'm getting weird. I'm looking
> for an example code that scan in a dir an return the content.
This is mydir.bb2 if found in an example drawer somewhere. I changed it so
that it's recursive. Whatever you mean. Either searching or displaying a dir
for both the following sourcecode should help.
----------[ Cut Here ]------------------------------------
;
; how to get file names of a DOS dirctory
;
; good example of using system structure in Blitz2
; also now using lset$ to format text output
;
; Made recursive by Serge Veugelers (sergev@cistron.nl)
NEWTYPE.MyFileInfo
_DiskKey.l
_DirEntryType.l
_FileName.b[108]
_Protection.l
_EntryType.l
_Size.l
_NumBlocks.l
ds_Days.l
ds_Minute.l
ds_Tick.l
_Comment.b[80]
_Reserved.b[36]
End NEWTYPE
NEWTYPE.DirInfo
fib.MyFileInfo
lock.l
End NEWTYPE
Dim MyDir.DirInfo(50) ; Maximum depth of 50
startdir$="hd1:"
Deep = 0
Gosub Scan
End
Scan:
path$ = startdir$
For i=0 To Deep-1
If i>0 Then path$+"/"
path$+Peek$(&MyDir(i)\fib\_FileName)
Next
MyDir(Deep)\lock=Lock_(&path$,-2) ;lock is dos system to access files
If Examine_(MyDir(Deep)\lock,MyDir(Deep)\fib)<>0 ;if we get lock on p$
Status.l=ExNext_(MyDir(Deep)\lock,MyDir(Deep)\fib) ;skip through files
While ExNext_(MyDir(Deep)\lock,MyDir(Deep)\fib) <> 0
For i=0 To Deep-1
Print "--"
Next
If MyDir(Deep)\fib\_DirEntryType<0 ;if its not a directory
NPrint LSet$(Peek$(&MyDir(Deep)\fib\_FileName),20)
;Print LSet$(Str$(MyDir(Deep)\fib\_Size),10)
;NPrint Date$(MyDir(Deep)\fib\ds_Days)
Else
fi$=Peek$(&MyDir(Deep)\fib\_FileName):NPrint Right$(String$("-",30)+"[ "+fi$,32)," ]--->"
Deep+1
Gosub Scan
Deep-1
EndIf
Wend
EndIf
UnLock_ MyDir(Deep)\lock
Return
-----------[ End of SourceCode ]-----------------------------------------------------------------